package com.zhixiang.wbl.visitor.Utils;

import android.util.Log;

import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.zhixiang.wbl.visitor.Constant.Constant;
import com.zhixiang.wbl.visitor.Helper.BaseCallback;
import com.zhixiang.wbl.visitor.Helper.OkHttpHelper;
import com.zhixiang.wbl.visitor.model.location.RootLocation;

/**
 * Created by dongzhixiang on 16/5/31.
 */
public class LocationUtil
{
    private int userID;
    private OnGetLocationListener mListener;
    public LocationUtil(int user_id,OnGetLocationListener mListener)
    {
        this.userID = user_id;
        this.mListener = mListener;
    }
   // 获取当前的位置经纬度信息
   public void getLocation()
   {
       String url = Constant.LOCATION_GET_URL+"?userId="+userID;
       OkHttpHelper.getInstance().get(url, new BaseCallback<RootLocation>()
       {
           @Override
           public void onBeforeRequest(Request request)
           {

           }

           @Override
           public void onFailure(Request request, Exception e)
           {

           }

           @Override
           public void onResponse(Response response)
           {

           }

           @Override
           public void onSuccess(Response response, RootLocation rootLocation)
           {
               if (200==rootLocation.getCode())
               {
                   mListener.onSuccess(rootLocation);
                   Log.e("LocationUtil", "onSuccess: "+rootLocation);
               }
               else
               {
                   mListener.onError(rootLocation.getMessage(),rootLocation.getCode());
               }
           }

           @Override
           public void onError(Response response, int code, Exception e)
           {
              mListener.onError(response.message(),code);
               Log.e("LocationUtil", "onError: ");
           }
       });
   }
   public interface OnGetLocationListener
   {
       void onSuccess(RootLocation rootLocation);
       void onError(String message, int code);
   }
}
